package com.dehui.traders.ui.stockdetail.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.ui.stockdetail.bean.StockCapital;
import com.dehui.traders.widgets.BaseViewHolder;
import com.dehui.traders.widgets.CommonAdapter;

import java.util.List;

import me.goldze.mvvmhabit.utils.Utils;

public class StockCaptialAdapter extends CommonAdapter<StockCapital>{

    private final Context context;

    public StockCaptialAdapter(Context context, List<StockCapital> mDatas, int itemLayoutId) {
        super(context, mDatas, itemLayoutId);
        this.context = context;
    }

    @Override
    public void convert(BaseViewHolder helper, StockCapital item, int position) {
        TextView tvTitle = helper.getView(R.id.tv_title);
        TextView tvContent0 = helper.getView(R.id.tv_content0);
        TextView tvContent1 = helper.getView(R.id.tv_content1);

        tvTitle.setText(item.getName());

        String outamount = item.getNetamount();
        float val = Utils.stringToFloat(outamount);
        tvContent0.setText(Utils.doubleToString(val / 10000) + "万");

        float ratio = Utils.stringToFloat(item.getAvg_changeratio());
        tvContent1.setText(Utils.doubleToString(ratio * 100) + "%");

        if (tvContent0.getText().toString().startsWith("-")){
            tvContent0.setTextColor(ContextCompat.getColor(context,R.color.green));
        }else{
            tvContent0.setTextColor(ContextCompat.getColor(context,R.color.red));
        }
        if (tvContent1.getText().toString().startsWith("-")){
            tvContent1.setTextColor(ContextCompat.getColor(context,R.color.green));
        }else{
            tvContent1.setTextColor(ContextCompat.getColor(context,R.color.red));
        }

    }
}
